package com.oa.ylms.apps.business.archives.impl;

import java.util.List;

import com.oa.ylms.apps.business.archives.IRecordCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.archives.IRecordCategoryDao;
import com.oa.ylms.apps.entity.archives.RecordCategoryValue;

public class RecordCategoryServiceImpl implements IRecordCategoryService {
	private RecordCategoryValue recordCategory;
	private IRecordCategoryDao categoryDao;

	@Override
	public int addRecordCategory(String categoryName) throws Exception {
		recordCategory.setCategoryName(categoryName);
		recordCategory.setStates(IDEDStates.ENABLE);
		return categoryDao.addRecordCategory(recordCategory);
	}

	@Override
	public boolean deleteRecordCategory(int categoryId) throws Exception {
		recordCategory = queryByCategoryId(categoryId);
		if(recordCategory != null){
			recordCategory.setStates(IDEDStates.DELETE);
			return categoryDao.editRecordCategory(recordCategory);
		}
		return false;
	}

	@Override
	public boolean modifyRecordCategory(int categoryId, String categoryName)
			throws Exception {
		recordCategory = queryByCategoryId(categoryId);
		if(recordCategory != null){
			recordCategory.setCategoryName(categoryName);
			return categoryDao.editRecordCategory(recordCategory);
		}
		return false;
	}

	@Override
	public RecordCategoryValue queryByCategoryId(int categoryId)
			throws Exception {
		recordCategory.setCategoryId(categoryId);
		return categoryDao.queryByCategoryId(recordCategory);
	}

	@Override
	public List<RecordCategoryValue> queryRecordCategory(Integer states)
			throws Exception {
		recordCategory.setStates(states);
		return categoryDao.queryRecordCategory(recordCategory);
	}

	@Override
	public boolean toDisable(int categoryId) throws Exception {
		recordCategory = queryByCategoryId(categoryId);
		if(recordCategory != null){
			recordCategory.setStates(IDEDStates.DISABLE);
			return categoryDao.editRecordCategory(recordCategory);
		}
		return false;
	}

	@Override
	public boolean toEnable(int categoryId) throws Exception {
		recordCategory = queryByCategoryId(categoryId);
		if(recordCategory != null){
			recordCategory.setStates(IDEDStates.ENABLE);
			return categoryDao.editRecordCategory(recordCategory);
		}
		return false;
	}
	
	public RecordCategoryValue getRecordCategory() {
		return recordCategory;
	}

	public void setRecordCategory(RecordCategoryValue recordCategory) {
		this.recordCategory = recordCategory;
	}

	public IRecordCategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(IRecordCategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

}
